<?php

namespace App\Http\Controllers\Erp;

use App\CodeResponse;
use App\Repositories\Sale\SaleOrderRepository;
use App\Services\Sale\SaleOrderService;
use Illuminate\Http\Request;

class SaleOrderController extends ErpController
{

    protected $saleOrderRepository;


    public function __construct(SaleOrderRepository $saleOrderRepository)
    {
        $this->saleOrderRepository = $saleOrderRepository;

    }


    //  //创建销售订单并现金支付销售订单
    public function createWithCashPay(Request $request)
    {
        //商品ID-商品数量，门店ID ，收款人,机器ID(优惠券）
        $input=$request->input();
        $flag=SaleOrderService::getInstance()->createOrderWithCashPay($input);
        return $this->failOrSuccess($flag, CodeResponse::CREATED_FAIL, $flag);
    }


    //查看销售订单列表

    public function list(Request $request)
    {
        $input = $request->input();

        if(empty($input['is_all'])){
            $list = $this->saleOrderRepository->getList();
            return $this->paginate($list);
        }else{
            $list = $this->saleOrderRepository->getAll();
            return $this->success($list);
        }


    }


}